package 线程中断;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-10-08
 * Time: 10:29
 */
public class demo1 {
    public volatile static boolean Q = false;
    public static void main1(String[] args) throws InterruptedException {
        Thread t = new Thread(){
            @Override
            public void run() {
                while(!Q){

                }
                System.out.println("t线程结束");
            }
        };
        t.start();
        System.out.println("t线程执行2s后结束");
        Thread.sleep(2000);
        Q = true;
    }

    public static void main(String[] args) {
        Thread t = new Thread(){
            @Override
            public void run() {
                while (true){

                }
            }
        };
        t.start();
    }
}
